/**
 * 
 */
package com.snapp.web.actions.templates;

import javax.servlet.http.HttpServletRequest;

import com.oreilly.servlet.MultipartRequest;
import com.snapp.web.SNAppAccess;
import com.snapp.web.agents.TemplateAgent;

/**
 * @author Kile
 *
 */
public class Save extends com.snapp.web.actions.secure.Save {

	public String execute(HttpServletRequest req) {

		try {
			MultipartRequest mpr = new MultipartRequest(req, "C:/tmp", 100 * 1024 * 1024);
			if (SNAppAccess.isSecure(mpr,req)) {
				TemplateAgent ta = new TemplateAgent();
				setObject(ta.saveTemplate(consolidateWriteMap(mpr)));
			}
		} catch(Exception e) {
			log("Unknown error saving template!", e);
			setResults(RESULT_CODE_ERROR, "Error saving template!");
		}
		
		return snappResponse(req);
	}
	
}
